package com.ruoyi.report_jl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_jl.domain.bo.ReportJlXjlmdxsljlbBsInfoBo;
import com.ruoyi.report_jl.domain.vo.ReportJlXjlmdxsljlbBsInfoVo;
import com.ruoyi.report_jl.domain.ReportJlXjlmdxsljlbBsInfo;
import com.ruoyi.report_jl.mapper.ReportJlXjlmdxsljlbBsInfoMapper;
import com.ruoyi.report_jl.service.IReportJlXjlmdxsljlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 细集料密度吸水率记录Service业务层处理
 *
 * @author tll
 * @date 2024-07-31
 */
@RequiredArgsConstructor
@Service
public class ReportJlXjlmdxsljlbBsInfoServiceImpl implements IReportJlXjlmdxsljlbBsInfoService {

    private final ReportJlXjlmdxsljlbBsInfoMapper baseMapper;

    /**
     * 查询细集料密度吸水率记录
     */
    @Override
    @FIllBasicInfo
    public ReportJlXjlmdxsljlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询细集料密度吸水率记录列表
     */
    @Override
    public TableDataInfo<ReportJlXjlmdxsljlbBsInfoVo> queryPageList(ReportJlXjlmdxsljlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportJlXjlmdxsljlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportJlXjlmdxsljlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询细集料密度吸水率记录列表
     */
    @Override
    public List<ReportJlXjlmdxsljlbBsInfoVo> queryList(ReportJlXjlmdxsljlbBsInfoBo bo) {
        LambdaQueryWrapper<ReportJlXjlmdxsljlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportJlXjlmdxsljlbBsInfo> buildQueryWrapper(ReportJlXjlmdxsljlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportJlXjlmdxsljlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, ReportJlXjlmdxsljlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, ReportJlXjlmdxsljlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportJlXjlmdxsljlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportJlXjlmdxsljlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportJlXjlmdxsljlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportJlXjlmdxsljlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportJlXjlmdxsljlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportJlXjlmdxsljlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportJlXjlmdxsljlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(bo.getYangpsj() != null, ReportJlXjlmdxsljlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportJlXjlmdxsljlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportJlXjlmdxsljlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportJlXjlmdxsljlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportJlXjlmdxsljlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportJlXjlmdxsljlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportJlXjlmdxsljlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportJlXjlmdxsljlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobmc()), ReportJlXjlmdxsljlbBsInfo::getBaobmc, bo.getBaobmc());
        lqw.eq(StringUtils.isNotBlank(bo.getBaobbh()), ReportJlXjlmdxsljlbBsInfo::getBaobbh, bo.getBaobbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportJlXjlmdxsljlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancr()), ReportJlXjlmdxsljlbBsInfo::getJiancr, bo.getJiancr());
        lqw.eq(StringUtils.isNotBlank(bo.getJilr()), ReportJlXjlmdxsljlbBsInfo::getJilr, bo.getJilr());
        lqw.eq(StringUtils.isNotBlank(bo.getFuhr()), ReportJlXjlmdxsljlbBsInfo::getFuhr, bo.getFuhr());
        lqw.eq(bo.getRiq() != null, ReportJlXjlmdxsljlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportJlXjlmdxsljlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportJlXjlmdxsljlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportJlXjlmdxsljlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(bo.getBiaogmdHgm1() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdHgm1, bo.getBiaogmdHgm1());
        lqw.eq(bo.getBiaogmdWm1() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdWm1, bo.getBiaogmdWm1());
        lqw.eq(bo.getBiaogmdPm1() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdPm1, bo.getBiaogmdPm1());
        lqw.eq(bo.getBiaogmdSw1() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdSw1, bo.getBiaogmdSw1());
        lqw.eq(bo.getBiaogmdWmd1() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdWmd1, bo.getBiaogmdWmd1());
        lqw.eq(bo.getBiaogmdDjmd1() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdDjmd1, bo.getBiaogmdDjmd1());
        lqw.eq(bo.getBiaogmdHgm2() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdHgm2, bo.getBiaogmdHgm2());
        lqw.eq(bo.getBiaogmdWm2() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdWm2, bo.getBiaogmdWm2());
        lqw.eq(bo.getBiaogmdPm2() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdPm2, bo.getBiaogmdPm2());
        lqw.eq(bo.getBiaogmdSw2() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdSw2, bo.getBiaogmdSw2());
        lqw.eq(bo.getBiaogmdWmd2() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdWmd2, bo.getBiaogmdWmd2());
        lqw.eq(bo.getBiaogmdDjmd2() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdDjmd2, bo.getBiaogmdDjmd2());
        lqw.eq(bo.getBiaogmdPjz() != null, ReportJlXjlmdxsljlbBsInfo::getBiaogmdPjz, bo.getBiaogmdPjz());
        lqw.eq(bo.getDuijmdTj1() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdTj1, bo.getDuijmdTj1());
        lqw.eq(bo.getDuijmdM11() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdM11, bo.getDuijmdM11());
        lqw.eq(bo.getDuijmdM21() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdM21, bo.getDuijmdM21());
        lqw.eq(bo.getDuijmdMd1() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdMd1, bo.getDuijmdMd1());
        lqw.eq(bo.getDuijmdTj2() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdTj2, bo.getDuijmdTj2());
        lqw.eq(bo.getDuijmdM12() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdM12, bo.getDuijmdM12());
        lqw.eq(bo.getDuijmdM22() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdM22, bo.getDuijmdM22());
        lqw.eq(bo.getDuijmdMd2() != null, ReportJlXjlmdxsljlbBsInfo::getDuijmdMd2, bo.getDuijmdMd2());
        lqw.eq(StringUtils.isNotBlank(bo.getXislFf1()), ReportJlXjlmdxsljlbBsInfo::getXislFf1, bo.getXislFf1());
        lqw.eq(bo.getXislDz1() != null, ReportJlXjlmdxsljlbBsInfo::getXislDz1, bo.getXislDz1());
        lqw.eq(StringUtils.isNotBlank(bo.getXislFf2()), ReportJlXjlmdxsljlbBsInfo::getXislFf2, bo.getXislFf2());
        lqw.eq(bo.getXislDz2() != null, ReportJlXjlmdxsljlbBsInfo::getXislDz2, bo.getXislDz2());
        lqw.eq(bo.getXislPjz() != null, ReportJlXjlmdxsljlbBsInfo::getXislPjz, bo.getXislPjz());
        return lqw;
    }

    /**
     * 新增细集料密度吸水率记录
     */
    @Override
    public Boolean insertByBo(ReportJlXjlmdxsljlbBsInfoBo bo) {
        ReportJlXjlmdxsljlbBsInfo add = BeanUtil.toBean(bo, ReportJlXjlmdxsljlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改细集料密度吸水率记录
     */
    @Override
    public Boolean updateByBo(ReportJlXjlmdxsljlbBsInfoBo bo) {
        ReportJlXjlmdxsljlbBsInfo update = BeanUtil.toBean(bo, ReportJlXjlmdxsljlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportJlXjlmdxsljlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除细集料密度吸水率记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
